#ifndef __POINT_ENTRY_H__
#define __POINT_ENTRY_H__

#include "tlm.h"
#include "PointStruct.h"

#include <iostream>
#include <stdexcept>
#include <vector>

class PointEntry {
public:
  PointEntry();
  PointEntry(int id, int entry_num);
  ~PointEntry();

  void addPoint(int index, PointStruct* point);
  void removePoint(int index);  // 删除指定位置的 PointStruct
  PointStruct* getPoint(int index) const; // 获取指定位置的 PointStruct
  PointStruct* popPoint(int index); // 获取并删除指定位置的 PointStruct
  void pushPoint(PointStruct* point); // 将 PointStruct 插入到第一个空位
  void printStatus() const;
  int getPointNum() const; // 获取非 false 的条目数量
  bool hasSameZcrdPoint(const PointStruct& point) const;
  PointStruct* findAndPopClosestPoint(const PointStruct& point, bool pop = true); // 根据传入的 Point 找到与之最接近的 Point，并选择是否从 Entry 中删除

private:
  const int m_ID;
  const int m_ENTRY_NUM;
  PointStruct** m_point_entry;
  bool* m_status_entry;
};


/*
int sc_main(int argc, char* argv[]) {
  try {
    PointEntry entry(1, 8);

    // 添加两个点
    entry.pushPoint(new PointStruct(1, 2, 3));
    entry.pushPoint(new PointStruct(4, 5, 6));

    PointStruct pointToCheck(0, 0, 3);
    if (entry.hasSameZcrdPoint(pointToCheck)) {
      std::cout << "Entry contains a point with the same z_crd." << std::endl;
      entry.pushPoint(&pointToCheck);
    } else {
      std::cout << "Entry does not contain a point with the same z_crd." << std::endl;
    }

    std::cout << "Number of valid entries: " << entry.getPointNum() << std::endl;
    entry.removePoint(0);
    std::cout << "Number of valid entries: " << entry.getPointNum() << std::endl;

    // 打印状态
    entry.printStatus();

    // 获取并打印第 1 个点的信息
    PointStruct* point = entry.popPoint(2);
    if (point) {
      std::cout << "Point at index 1: ";
      point->print();
    } else {
      std::cout << "No point at index 1" << std::endl;
    }
    std::cout << "Number of valid entries: " << entry.getPointNum() << std::endl;

    // 获取无效索引
    try {
      PointStruct* invalidPoint = entry.getPoint(10);
    } catch (const std::out_of_range& e) {
      std::cout << "Error: " << e.what() << std::endl;
    }
  } catch (const std::exception& e) {
    std::cerr << "Error: " << e.what() << std::endl;
  }

  return 0;
}
*/
#endif /* __POINT_ENTRY_H__ */
